//
//  NSString+time.m
//  aiteshangcheng
//
//  Created by caominglei on 2018/4/20.
//  Copyright © 2018年 aite. All rights reserved.
//

#import "NSString+time.h"

@implementation NSString (time)

/**
 秒数转换为年月日时分秒的时间
 */
+ (NSString *)ConvertStrToTime:(NSString *)timeStr

{
    
    long long time=[timeStr longLongValue];
    
    NSDate *d = [[NSDate alloc]initWithTimeIntervalSince1970:time];
    
    NSDateFormatter *formatter = [[NSDateFormatter alloc]init];
    
    [formatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
    
    NSString*timeString=[formatter stringFromDate:d];
    
    return timeString;
    
}
/*
 把秒转换成时间格式：
 */
+(NSString *)getMMSSFromSS:(NSString *)totalTime{
    NSInteger seconds = [totalTime integerValue];
    //format of hour
    NSString *str_hour = [NSString stringWithFormat:@"%02ld",seconds/3600];
    //format of minute
    NSString *str_minute = [NSString stringWithFormat:@"%02ld",(seconds%3600)/60];
    //format of second
    NSString *str_second = [NSString stringWithFormat:@"%02ld",seconds%60];
    //format of time
    NSString *format_time = [NSString stringWithFormat:@"%@:%@:%@",str_hour,str_minute,str_second];
    return format_time;
    
}
/*
把毫秒转换成时间格式：
*/

//将时间数据（毫秒）转换为天和小时
+ (NSString*)getOvertime:(NSString*)mStr
{
    long msec = [mStr longLongValue];
    
    if (msec <= 0)
    {
        return @"";
    }
    
    NSInteger d = msec/1000/60/60/24;
    NSInteger h = msec/1000/60/60%24;
    //NSInteger  m = msec/1000/60%60;
    //NSInteger  s = msec/1000%60;
    
    NSString *_tStr = @"";
    NSString *_dStr = @"";
    NSString *_hStr = @"";
    NSString *_hTimeType = @"defaultColor";
    
    if (d > 0)
    {
        _dStr = [NSString stringWithFormat:@"%ld天",d];
    }
    
    if (h > 0)
    {
        _hStr = [NSString stringWithFormat:@"%ld小时",h];
    }
    
    //小于2小时 高亮显示
    if (h > 0 && h < 2)
    {
        _hTimeType = @"hightColor";
    }
    
    _tStr = [NSString stringWithFormat:@"%@:%@:%@",_dStr,_hStr,_hTimeType];
    
    return _tStr;
}
@end
